<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin = new admin();
$admin->canView($_SERVER['PHP_SELF']);
ob_start("sanitize_output"); 
$row=$admin->getForm($_GET['id']);

$f=file_get_contents($_SERVER['DOCUMENT_ROOT'].'/inc/form_'.$row['token'].'.php');
$form_content=str_replace("</textarea>","</text-area>",$f);
?>
<form class="inline" method="post" enctype="multipart/form-data" action="/admin/resources/php/requests/actions/save-form.php">
<input type="hidden" class="settings" value='{"buttonWaitingValue":"Adding form","updateNode":"#response"}' />	
<input type="hidden" value="<?php echo((string)$row['_id']); ?>" name="form_id" id="form_id" />
<input type="hidden" value="<?php echo((string)$row['token']); ?>" name="form_token" id="form_token" />


<input type="submit" class="button" value="Save changes" style="float:right;" />
<h1>Editing '<?php echo($row['form_name']); ?>'</h1>
<table width="100%">
<tr valign="top">
	<td width="26%"><label>Form Name:</label><br />
<input type="text" class="comment-field req" name="form_name" id="form_name" style="width:250px;" value="<?php echo($row['form_name']); ?>" />
</td>
	<td width="16%"> <label>Processing button value:</label><br />
        <input type="text" class="comment-field req" name="form_button_waiting_value" id="form_button_waiting_value"  value="<?php echo($row['button_waiting_value']); ?>" style="width:150px;" />
 	</td>
    <td width="16%">
    <label>Method:</label><br />
        <select class="form-field" name="form_method" id="form_method" style="width:156px;"><?php echo($admin->methodsAsOptions($row['form_method'])); ?></select>
    </td>
    <td width="16%"><label>Process Inline:</label><br />
        <select class="form-field" name="form_inline" id="form_inline" style="width:156px;"><?php echo($admin->selectYesNo($row['inline'])); ?></select></td>
    <td width="26%"><label>Enctype:</label><br />
        <select class="form-field" name="form_enctype" id="form_enctype" style="width:156px;"><?php echo($admin->enctypesAsOptions($row['enctype'])); ?></select></td>
</tr>
</table>

<div style="float:left;width:48%;">
	<label>Form Markup</label>
    <p class="hint">NOT including &lt;form&gt;</p>
<textarea name="form_markup" id="form_markup" style="width:100%;height:400px;" class="form-field req"><?php echo($form_content); ?></textarea>
</div>
<div style="float:right;width:48%;">
	<label>Processing Logic</label>
    <p class="hint">Including &lt;?php ?&gt; tags</p>
<textarea name="form_logic" id="form_logic" style="width:100%;height:400px;" class="form-field req"><?php echo(file_get_contents($_SERVER['DOCUMENT_ROOT'].'/inc/logic_'.$row['token'].'.php')); ?></textarea>

</div>
</form>